package com.arsn.myf.flow.controller;

import com.arsn.myf.common.util.result.R;
import com.arsn.myf.flow.entity.Flow;
import com.arsn.myf.flow.service.CommonTaskService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 公用任务处理控制层
 * @author zhongrj
 * @since 2022-11-04
 */
@RestController
@RequestMapping("/common/task")
@Api(value = "公用任务处理", tags = "公用任务处理")
public class CommonTaskController {

    @Autowired
    private CommonTaskService commonTaskService;

    /**
     * 已发事务列表页
     * @param page
     * @param flow
     * @return
     */
    @GetMapping("send-list")
    @ApiOperation(value = "已发事务列表页")
    public R sendList(@ApiParam("流程信息") Page<Flow> page, Flow flow) {
        IPage<Flow> pages = commonTaskService.selectSendPage(page, flow);
        return R.data(pages);
    }

    /**
     * 待签收事务列表页
     * @param page
     * @param flow
     * @return
     */
    @GetMapping("claim-list")
    @ApiOperation(value = "待签收事务列表页")
    public R claimList(@ApiParam("流程信息") Page<Flow> page, Flow flow) {
        IPage<Flow> pages = commonTaskService.selectClaimPage(page, flow);
        return R.data(pages);
    }

    /**
     * 待处理事务列表页
     * @param page
     * @param flow
     * @return
     */
    @GetMapping("todo-list")
    @ApiOperation(value = "待处理事务列表页")
    public R todoList(@ApiParam("流程信息") Page<Flow> page, Flow flow) {
        IPage<Flow> pages = commonTaskService.selectTodoPage(page, flow);
        return R.data(pages);
    }

    /**
     * 办结事务列表页
     * @param page
     * @param flow
     * @return
     */
    @GetMapping("done-list")
    @ApiOperation(value = "办结事务列表页")
    public R doneList(@ApiParam("流程信息") Page<Flow> page, Flow flow) {
        IPage<Flow> pages = commonTaskService.selectDonePage(page, flow);
        return R.data(pages);
    }

    /**
     * 历史流转列表
     * @param flow
     * @return
     */
    @GetMapping("history-list")
    @ApiOperation(value = "历史流转列表")
    public R historyList(Flow flow) {
        return R.data(commonTaskService.historyList(flow));
    }

    /**
     * 签收任务（流程）
     * @param taskId 任务id
     * @return
     */
    @PostMapping("/claim-task")
    @ApiOperation(value = "签收任务")
    public R claimTask(String taskId){
        return R.status(commonTaskService.claimTask(taskId));
    }

    /**
     * 完成任务（流程）
     * @param flow
     * @return
     */
    @PostMapping("/complete-task")
    @ApiOperation(value = "完成任务")
    public R completeTask(@RequestBody Flow flow){
        return R.status(commonTaskService.completeTask(flow));
    }
}
